package com.songcha.library_business.viewmodel

import android.app.Application
import com.alibaba.android.arouter.launcher.ARouter
import com.songcha.library_base.mvvm.base.BaseRepository
import com.songcha.library_base.mvvm.base.BaseViewModel
import com.songcha.library_base.mvvm.exception.LoginTokenInvalidException
import com.songcha.library_business.provider.ILogoutProvider
import com.songcha.library_business.proxy.userinfo.UserInfoManager

open class BaseErrorViewModel<R: BaseRepository>(app: Application):BaseViewModel<R>(app) {
    init {
        apiErrorListener=object :IOnApiErrorListener{
            override fun onApiError(e: Throwable) {
                if(e is LoginTokenInvalidException){
                    UserInfoManager.clearLogin()
                    ARouter.getInstance().build("/task/DailyTaskController").navigation()?.let {
                        (it as ILogoutProvider).onLogout()
                    }
                }
            }
        }
    }

}